<?php

use IDock\Printer\ProposalStatusPrinter;
use IDock\Visitor\EPolicyDownloadVisitor;
use IDock\Visitor\NonCar\NonCarInquiryVisitor;
use IDock\Visitor\NonCar\NonCarProductVisitor;
use IDock\Visitor\PolicyInfoVisitor;
use IDock\Visitor\PolicyPaymentVisitor;
use IDock\Visitor\Premium\PremiumCarTaxVisitor;
use IDock\Visitor\Premium\PremiumChargingPileVisitor;
use IDock\Visitor\Premium\PremiumCoverageVisitor;
use IDock\Visitor\Premium\PremiumExtInfoVisitor;
use IDock\Visitor\Premium\PremiumInquiryVisitor;
use IDock\Visitor\Premium\PremiumNoCarVisitor;
use IDock\Visitor\Premium\PremiumPolicyVisitor;
use IDock\Visitor\Premium\PremiumRelationVisitor;
use IDock\Visitor\Premium\PremiumUnderwritingVisitor;
use IDock\Visitor\Premium\PremiumVehicleVisitor;
use IDock\Visitor\ProposalRecallVisitor;
use IDock\Visitor\ProposalStatusVisitor;
use IDock\Visitor\RenewalInquiryVisitor;
use IDock\Visitor\UnderwritingRecallVisitor;
use IDock\Visitor\UploadFileVisitor;
use IDock\Visitor\VehicleActualValueVisitor;
use IDock\Visitor\VehicleModelVisitor;

require_once('./vendor/autoload.php');

$IDock = new \IDock\IDock\IDock();
$MACNConfig = '';
require_once('config.php');

$IDock->setBean('MACN', $MACNConfig);


global $testResponse;
$testResponse = '';

//$shortName = 'DAJIA';
$shortName = 'MACN';


$vin = 'LS4AAB3R69A161372';
$engineNo = '97BB037821';
$licenseNo = '粤WK3229';
$firstRegisterDate = '2009-10-20';
$vehicleModel = '长安SC6408D客车';

$biStartData = '2022-10-20 00:00:00';
$ciStartData = '2022-10-20 00:00:00';
$biEndData = '2023-10-19 23:59:59';
$ciEndData = '2023-10-19 23:59:59';

try {
//$engineNo = 'SVW71217DN';
//$vin = 'LSVGZ6183J2037364';
//续保查询接口
    if (0) {
        //续保查询接口
        $renewalInquiryVisitor = new RenewalInquiryVisitor();
        //车架号
        $renewalInquiryVisitor->vin = $vin;
        //发动机号
        $renewalInquiryVisitor->engineNo = $engineNo;
        //车牌号
        $renewalInquiryVisitor->licenseNo = $licenseNo;
        $renewalInquiryVisitor->argc['type'] = 1;
        $renewalInquiryVisitor->argc['operatorCode'] = 'PS17400611';

        $response = $IDock->renewalInquiry($shortName, $renewalInquiryVisitor);

        var_dump($response->isSuccess());
        var_dump($response->getError());

        /**
         * @var $printer \IDock\Printer\RenewalInquiryPrinter
         */
        $printer = $response->getPrinter();
        var_dump($printer->toArray());
        exit;
    }

//车辆车型查询接口
    if (0) {
        //车辆车型查询接口
        $vehicleModelVisitor = new VehicleModelVisitor();
        //车架号
        $vehicleModelVisitor->vin = $vin;
        //$vehicleModelVisitor->vin = '';
        //发动机号
        $vehicleModelVisitor->engineNo = $engineNo;
        //车牌号
        $vehicleModelVisitor->licenseNo = $licenseNo;
        //初登时间
        $vehicleModelVisitor->firstRegisterDate = $firstRegisterDate;
        //车型编码
        $vehicleModelVisitor->vehicleModel = $vehicleModel;
        //$vehicleModelVisitor->vehicleModel = '';
        $vehicleModelVisitor->argc['areaCode'] = '51';
        $vehicleModelVisitor->argc['cDptCde'] = '07000002';
        $vehicleModelVisitor->argc['brandName'] = '品牌';

        $response = $IDock->vehicleModel($shortName, $vehicleModelVisitor);
        var_dump($response->isSuccess());
        var_dump($response->getError());

        /**
         * @var $printer \IDock\Printer\VehicleModelPrinter
         */
        $printer  = $response->getPrinter();
        var_dump($printer->toArray());
        exit;
    }

//车辆实际价格
    if (0) {
        //车辆实际价格
        $vehicleActualValueVisitor = new VehicleActualValueVisitor();
        $vehicleActualValueVisitor->startDate = $biStartData;
        $vehicleActualValueVisitor->firstRegisterDate = $firstRegisterDate;
        $vehicleActualValueVisitor->firstRegisterDate = $firstRegisterDate;
        //车辆价格
        $vehicleActualValueVisitor->vehiclePrice = '44800.0';
        //能源类型
        $vehicleActualValueVisitor->energyType = 'E01';
        //是否新能源
        $vehicleActualValueVisitor->isNewEnergy = false;
        //使用性质
        $vehicleActualValueVisitor->useNatureCode = '01';
        //车辆用途
        $vehicleActualValueVisitor->causeType = '001';
        //车辆种类
        $vehicleActualValueVisitor->carKindCode = '100';
        //座位数
        $vehicleActualValueVisitor->vehicleSeat = '8';
        //荷载质量
        $vehicleActualValueVisitor->vehicleTonnage = '0';


        $response = $IDock->vehicleActualValue($shortName, $vehicleActualValueVisitor);
        var_dump($response->isSuccess());
        var_dump($response->getError());

        /**
         * @var $printer \IDock\Printer\VehicleActualValuePrinter
         */
        $printer = $response->getPrinter();
        var_dump($printer->toArray());
        exit;
    }

//询价前置
//保费计算
//核保
    if (0) {

        /**
         * 询价主信息
         */
        $premiumInquiryVisitor = new PremiumInquiryVisitor();
        //商业险起保日期
        $premiumInquiryVisitor->biStartData = $biStartData;
        //商业险终保日期
        $premiumInquiryVisitor->biEndData = $biEndData;
        //交强险起保日期
        $premiumInquiryVisitor->ciStartData = $ciStartData;
        //交强险终保日期
        $premiumInquiryVisitor->ciEndData = $ciEndData;
        //商业险即时生效
        $premiumInquiryVisitor->biEffectFlag = false;
        //交强险即时生效
        $premiumInquiryVisitor->ciEffectFlag = false;

        $premiumInquiryVisitor->isNewEnergy = false;

        /**
         * 车辆信息
         */
        $premiumVehicleVisitor = new PremiumVehicleVisitor();
        //是否新车
        $premiumVehicleVisitor->isNewVehicle = '0';
        //车架号
        $premiumVehicleVisitor->vin = $vin;
        //发动机号
        $premiumVehicleVisitor->engineNo = $engineNo;
        //车牌号
        $premiumVehicleVisitor->licenseNo = $licenseNo;
        //初登时间
        $premiumVehicleVisitor->firstRegisterDate = $firstRegisterDate;
        //过户时间
        $premiumVehicleVisitor->transferDate = '';
        //是否过户车
        $premiumVehicleVisitor->isTransfer = '';
        //发证时间
        $premiumVehicleVisitor->issueDate = '';
        //车型编码
        $premiumVehicleVisitor->vehicleModel = $vehicleModel;
        //车型编码代码
        $premiumVehicleVisitor->vehicleModelCode = 'CAD1857CQC';
        //$premiumVehicleVisitor->vehicleModelCode = 'BTYOSPUB0014';
        //车型名称
        $premiumVehicleVisitor->vehicleName = $vehicleModel;
        //车价
        $premiumVehicleVisitor->vehiclePrice = '78800';
        //车价含税
        $premiumVehicleVisitor->vehiclePriceTax = '78800';
        //协商价格
        $premiumVehicleVisitor->actualValue = '49959.2';
        //座位数
        $premiumVehicleVisitor->vehicleSeat = '8';
        //使用性质
        $premiumVehicleVisitor->useNatureCode = '01';
        //所属性质
        $premiumVehicleVisitor->attachNature = '01';
        //车辆用途
        $premiumVehicleVisitor->causeType = '001';
        //车辆种类
        $premiumVehicleVisitor->carKindCode = '100';
        //能源类型代码
        $premiumVehicleVisitor->energyTypeCode = 'E01';
        //号牌颜色代码
        $premiumVehicleVisitor->licenseColorCode = '01';
        //号牌种类代码
        $premiumVehicleVisitor->licenseTypeCode = '02';
        //交管车辆类型代码
        $premiumVehicleVisitor->vehicleStyleCode = 'K33';
        //功率
        $premiumVehicleVisitor->power = '79.0';
        //排量
        $premiumVehicleVisitor->vehicleExhaust = '1298.0';
        //整备质量
        $premiumVehicleVisitor->wholeWeight = '1090';
        //荷载质量
        $premiumVehicleVisitor->vehicleTonnage = '0.0';
        //进口标识
        $premiumVehicleVisitor->vehicleImport = 'I0';
        //是否能源车
        $premiumVehicleVisitor->isNewEnergy = '0';
        //纯电续航里程(公里)
        $premiumVehicleVisitor->pureRange = '';
        //车辆来历凭证编号
        $premiumVehicleVisitor->carCertificateNo = '';
        //开具车辆来历凭证所载日期
        $premiumVehicleVisitor->carCertificateDate = '';
        //车辆来历凭证种类代码
        $premiumVehicleVisitor->carCertificateType = '';
        $premiumVehicleVisitor->argc['carKind'] = '轿车';

        /**
         * 关系人
         */
        $premiumRelationVisitor = new PremiumRelationVisitor();
        //姓名
        $premiumRelationVisitor->name = '李旭桂';
        //联系方式
        $premiumRelationVisitor->mobile = '13814035500';
        //类型
        $premiumRelationVisitor->typeCode = 'R1';
        //证件类型
        $premiumRelationVisitor->certificateTypeCode = '01';
        //证件号码
        $premiumRelationVisitor->certificateNo = '445321198410191913';
        //地址
        $premiumRelationVisitor->address = '江苏省南京市秦淮区';
        //邮箱
        $premiumRelationVisitor->email = '13814035500@qq.com';
        //证件有效期
        $premiumRelationVisitor->certificateStartDate = '2023-10-13';
        //证件失效期
        $premiumRelationVisitor->certificateEndDate = '2043-10-13';

        /**
         * 缴税信息
         */
        $premiumCarTaxVisitor = new PremiumCarTaxVisitor();
        //缴税内心
        $premiumCarTaxVisitor->taxTypeCode = 'T01';
        //纳税人姓名
        $premiumCarTaxVisitor->taxpayerName = '李旭桂';
        //纳税人证件类型
        $premiumCarTaxVisitor->taxpayerCertificateTypeCode = '01';
        //纳税人证件号码
        $premiumCarTaxVisitor->taxpayerCertificateNo = '445321198410191913';
        //纳税人电话
        $premiumCarTaxVisitor->taxpayerPhone = '13814035500';
        //纳税起期
        $premiumCarTaxVisitor->taxStartDate = '2023-01-01';
        //纳税止期
        $premiumCarTaxVisitor->taxEndDate = '2024-01-01';
        //减免税方案代码
        $premiumCarTaxVisitor->taxReductionCode = '';
        //减免税原因代码
        $premiumCarTaxVisitor->taxReductionReasonCode = '';
        //税务机关名称
        $premiumCarTaxVisitor->taxDepartment = '';
        //税务机关代码
        $premiumCarTaxVisitor->taxDepartmentCode = '';
        //开具完税凭证地区代码
        $premiumCarTaxVisitor->taxPaidAreaCode = '';
        //完税凭证填发日期
        $premiumCarTaxVisitor->taxDocumentDate = '';
        //减免比例 百分比
        $premiumCarTaxVisitor->taxFreeRate = '';
        //减税金额 元
        $premiumCarTaxVisitor->taxExemption = '';
        //减免完税凭证号
        $premiumCarTaxVisitor->taxDocumentNumber = '';

        //险种

        //
        $premiumCoverageVisitor = new PremiumCoverageVisitor();
        $premiumCoverageVisitor->coverageCode = 'C04001';
        $premiumCoverageVisitor->amount = '10000';

        $premiumCoverageVisitor1 = new PremiumCoverageVisitor();
        $premiumCoverageVisitor1->coverageCode = 'C15001';
        $premiumCoverageVisitor1->amount = '40000';
        $premiumCoverageVisitor1->unitAmount = '10000';

        //
        $premiumCoverageVisitor2 = new PremiumCoverageVisitor();
        $premiumCoverageVisitor2->coverageCode = 'C03001';
        $premiumCoverageVisitor2->amount = '1000000';


        //新能源充电桩信息
        $premiumChargingPileVisitor = new PremiumChargingPileVisitor();

        $premiumChargingPileVisitor->seqNo = '1';
        //充电桩类型
        $premiumChargingPileVisitor->chargingPileKind = 'PK1';
        //充电桩安装地点类型
        $premiumChargingPileVisitor->chargingPileAddressType = 'PA1';
        //充电桩使用年限
        $premiumChargingPileVisitor->chargingPileYearLimit = 'PY1';
        //充电桩编码
        $premiumChargingPileVisitor->chargingPileCode = '123456';
        //充电桩型号
        $premiumChargingPileVisitor->chargingPileType = 'BCS100500';
        //充电桩地址
        $premiumChargingPileVisitor->chargingPileAddress = '地面充电桩';
        //损失保险保额
        $premiumChargingPileVisitor->lossAmount = '';
        //责任保险保额
        $premiumChargingPileVisitor->liabilityAmount = '10000';

        /**
         * 拓展信息
         */
        $premiumExtInfoVisitor = new PremiumExtInfoVisitor();
        //验车情况
        $premiumExtInfoVisitor->carCheckCode = '';
        //免验原因
        $premiumExtInfoVisitor->carCheckReasonKind = '';
        //验车人
        $premiumExtInfoVisitor->carChecker = '';
        //验车日期
        $premiumExtInfoVisitor->carCheckDate = '';
        //验车地点
        $premiumExtInfoVisitor->carAddress = '';
        //是否送修
        $premiumExtInfoVisitor->isMonopoly = '';
        //送修代码
        $premiumExtInfoVisitor->repairCode = '';
        //送修名称
        $premiumExtInfoVisitor->repairName = '';
        //自主定价系数
        $premiumExtInfoVisitor->selfPricingFactor = '';
        //自主核保系数
        $premiumExtInfoVisitor->underwritingFactor = '';
        //期望折扣
        $premiumExtInfoVisitor->expectedDiscount = '';
        //是否贷款车
        $premiumExtInfoVisitor->isLoanCar = '';
        //贷款机构名称
        $premiumExtInfoVisitor->loanOrg = '';

        //亚太拓展
        $premiumExtInfoVisitor->argc['certificateNo'] = '38964293749273428472';
        $premiumExtInfoVisitor->argc['carKind'] = '轿车';


        /**
         * 非车列表
         */
        $premiumNoCarVisitor = new NonCarInquiryVisitor();
        //投保份数
        $single = new NonCarProductVisitor();
        $premiumNoCarVisitor->nonCarListAppend($single);

        //添加车辆信息
        $premiumInquiryVisitor->setVehicleVisitor($premiumVehicleVisitor);
        //添加投保人
        $premiumInquiryVisitor->setApplicantVisitor($premiumRelationVisitor);
        //添加被保人
        $premiumInquiryVisitor->setInsuredVisitor($premiumRelationVisitor);
        //添加车主
        $premiumInquiryVisitor->setOwnerVisitor($premiumRelationVisitor);
        //车船税
        $premiumInquiryVisitor->setCarTaxVisitor($premiumCarTaxVisitor);
        //险种添加
        $premiumInquiryVisitor->coverageVisitorAppend($premiumCoverageVisitor1);
        $premiumInquiryVisitor->coverageVisitorAppend($premiumCoverageVisitor2);
        $premiumInquiryVisitor->coverageVisitorAppend($premiumCoverageVisitor);
        //新能源充电桩
        $premiumInquiryVisitor->chargingPileVisitorAppend($premiumChargingPileVisitor);
        //拓展信息
        $premiumInquiryVisitor->setExtInfoVisitor($premiumExtInfoVisitor);
        //非车信息
        $premiumInquiryVisitor->setNonCarInquiryVisitor($premiumNoCarVisitor);

//    //询价前置
//    $response = $IDock->preInquiry($shortName, $premiumInquiryVisitor);
//    var_dump($response->isSuccess());
//    var_dump($response->getError());
//    /**
//     * @var $printer \IDock\Printer\preInquiryPrinter;
//     */
//    $printer = $response->getPrinter();
//    var_dump($printer->toArray());
//    exit;

        //询价
        $response = $IDock->premiumInquiry($shortName, $premiumInquiryVisitor);
        var_dump($response->isSuccess());
        var_dump($response->getError());

        /**
         * @var $printer \IDock\Printer\Premium\PremiumInquiryPrinter;
         */
        $printer = $response->getPrinter();
        var_dump($printer);
        exit;

        /**
         * 核保信息
         */
        $premiumUnderwritingVisitor = new PremiumUnderwritingVisitor();
        $premiumUnderwritingVisitor->biInquiryNo = '599510803662023000190';
        $premiumUnderwritingVisitor->ciInquiryNo = '599510803602023000152';

        $premiumUnderwritingVisitor->agreement = [
            '本保单保险费为含税金额，其中不含税保险费**元、增值税**元。',
            '温馨提示：尊敬的客户，投保次日起，您可通过本网站、客服电话、营业网点核实保单及理赔等信息。若对查询结果有异议，请联系本公司。联系方式：网址：http://www.e-acic.com 电话：95544',
            '2020年3季度，我司综合偿付能力充足率为539.71%，符合监管要求。2020年3季度，我司风险综合评级（分类监管）为A。',
            '四川保险业消费者权益保护中心维权热线：028-841-12378。',
            '因履行本保险合同发生的争议，除条款约定的合同争议解决方式外，还可向四川保险业消费者权益保护中心申请调解。',
            '本车险相关信息将由本公司共享至四川省保险行业协会，用于（且仅用于）行业与交管等政府部门进行信息共享，用于风险防范、社会管理等目的。'
        ];

        $premiumInquiryVisitor->setUnderwritingVisitor($premiumUnderwritingVisitor);

        //核保
        $response = $IDock->underwriting($shortName, $premiumInquiryVisitor);

        var_dump($response->isSuccess());
        var_dump($response->getError());

        /**
         * @var $printer \IDock\Printer\PremiumUnderwritingPrinter;
         */
        $printer = $response->getPrinter();

        if($response->isSuccess()) var_dump($printer->toArray());
        exit;
    }

//支付
    if (0) {
        $policyPaymentVisitor = new PolicyPaymentVisitor();
        $policyPaymentVisitor->inquiryNo = '599510803602023000184';
        $policyPaymentVisitor->biInquiryNo = '';
        $policyPaymentVisitor->ciInquiryNo = '599510803602023000184';

        $response = $IDock->policyPayment($shortName, $policyPaymentVisitor);

        var_dump($response->isSuccess());
        var_dump($response->getError());
        /**
         * @var $printer \IDock\Printer\PolicyPaymentPrinter
         */
        $printer = $response->getPrinter();

        var_dump($printer->toArray());
        exit;
    }

//影像资料上传
    if (0) {
        $uploadFileVisitor = new UploadFileVisitor();
        $uploadFileVisitor->inquiryNo = '599510803602023000152599510803662023000190';
        $uploadFileVisitor->biInquiryNo = '599510803662023000190';
        $uploadFileVisitor->ciInquiryNo = '599510803602023000152';
        $uploadFileVisitor->argc['preProposalTopNo'] = 'Z04021700000000202300166287';
        $uploadFileVisitor->fileAppend('10010', 'https://p0.itc.cn/q_70/images03/20220512/77ed76720a1f40ef94948761dda05655.jpg');

        $response = $IDock->uploadFile($shortName, $uploadFileVisitor);

        var_dump($response->isSuccess());
        var_dump($response->getError());

        /**
         * @var  $printer \IDock\Printer\UploadFilePrinter
         */
        $printer = $response->getPrinter();

        var_dump($printer->toArray());
        exit;
    }

//投保单查询
    if (0) {
        $proposalStatusVisitor = new ProposalStatusVisitor();

        $proposalStatusVisitor->inquiryNo = '05021700004108122023000033';
        $proposalStatusVisitor->biInquiryNo = '05021700004108122023000033';
        $proposalStatusVisitor->ciInquiryNo = '05021700004108062023000035';
        $proposalStatusVisitor->argc['preProposalTopNo'] = 'Z04021700000000202300166631';
        $response = $IDock->proposalStatus($shortName, $proposalStatusVisitor);

        var_dump($response->isSuccess());
        var_dump($response->getError());

        /*** @var $printer ProposalStatusPrinter; */
        $printer = $response->getPrinter();

        var_dump($printer);
        exit;
    }

//撤单
    if (0) {
        $proposalRecallVisitor = new ProposalRecallVisitor();

        $proposalRecallVisitor->inquiryNo = '599510803682023000036';
        $proposalRecallVisitor->biInquiryNo = '';
        $proposalRecallVisitor->ciInquiryNo = '599510803682023000036';
        $proposalRecallVisitor->reason = '客户注销';
        $proposalRecallVisitor->argc['OrgCode'] = '51080503';

        $response = $IDock->proposalRecall($shortName, $proposalRecallVisitor);

        var_dump($response->isSuccess());
        var_dump($response->getError());

        /**
         * @var $printer \IDock\Printer\ProposalRecallPrinter
         */
        $printer = $response->getPrinter();
        var_dump($printer->toArray());
        exit;
    }

//核保撤单
    if (0) {
        $underwritingRecallVisitor = new UnderwritingRecallVisitor();

        $underwritingRecallVisitor->inquiryNo = '599510803682023000036';
        $underwritingRecallVisitor->biInquiryNo = '';
        $underwritingRecallVisitor->ciInquiryNo = '599510803682023000036';
        $underwritingRecallVisitor->reason = '投保注销';
        $underwritingRecallVisitor->argc['OrgCode'] = '51080503';

        $response = $IDock->underwritingRecall($shortName,$underwritingRecallVisitor);

        var_dump($response->isSuccess());
        var_dump($response->getError());

        /**
         * @var $printer \IDock\Printer\UnderwritingRecallPrinter
         */
        $printer = $response->getPrinter();
        var_dump($printer->toArray());
        exit;

    }

//电子保单下载
    if (0) {
        $EPolicyDownloadVisitor = new EPolicyDownloadVisitor();

        $EPolicyDownloadVisitor->policyNo = '299510803602023000033';
        $EPolicyDownloadVisitor->biPolicyNo = '299510803602023000033';
        $EPolicyDownloadVisitor->ciPolicyNo = '299510803602023000033';
        $EPolicyDownloadVisitor->argc['preProposalTopNo'] = 'Z04021700000000202300166496';
        $EPolicyDownloadVisitor->argc['noCarProposalNo'] = '05021705161184202400000991';
        $response = $IDock->EPolicyDownload($shortName, $EPolicyDownloadVisitor);

//        var_dump($response->isSuccess());
//        var_dump($response->getError());
        var_dump($response->printer->finish);
        var_dump($response->noCarUrl);
//        var_dump($response->ciUrl);
//        var_dump($response->biUrl);

        /**
         * @var $printer \IDock\Printer\EPolicyDownloadPrinter
         */
        $printer = $response->getPrinter();
        var_dump($printer);
        exit;
    }

//保单详情
    if (0) {
        $policyInfoVisitor = new PolicyInfoVisitor();

        $policyInfoVisitor->policyNo = '299510803602023000033';

        $response = $IDock->policyInfo($shortName, $policyInfoVisitor);
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getPrinter()->toArray());
        exit;
    }

    //非车产品列表
    if(1){
        $nonCarProductListVisitor = new \IDock\Visitor\NonCar\NonCarProductListVisitor();
        $nonCarProductListVisitor->seats = '5';
        $nonCarProductListVisitor->argc['companyCode'] = '0217051604';
        $response = $IDock->nonCarProductList($shortName,$nonCarProductListVisitor);

        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->printer);
    }

}catch (Exception $e){
    var_dump($e->getMessage());
}
